package maquinavotar;

import java.awt.Dimension;
import java.util.ArrayList;
import javax.swing.JPanel;
import maquinavotar.dto.CandidateDTO;
import maquinavotar.dto.ElectionDTO;
import maquinavotar.view.ConfirmVoteScreen;
import maquinavotar.view.InitialScreen;
import maquinavotar.view.SelectionVoteScreen;
import org.jdesktop.application.Application;
import org.jdesktop.application.SingleFrameApplication;

/**
 * The main class of the application.
 */
public class MaquinaVotarApp extends SingleFrameApplication {

    public ArrayList<CandidateDTO> cands = null;
    public ArrayList<ElectionDTO> vote = null;
    
    ArrayList<JPanel> screens = new ArrayList<JPanel>();
    InitialScreen initialScreen = null;
    SelectionVoteScreen selectionVoteScreen = null;
    ConfirmVoteScreen confirmVoteScreen = null;
    
     /**
     * At startup create and show the main frame of the application.
     */
    @Override protected void startup() {
        this.getMainFrame().setPreferredSize(new Dimension(500, 300));
        this.getMainFrame().setResizable(false);
        
        initialScreen = InitialScreen.getInstance(this); // This is screen 0
        selectionVoteScreen = SelectionVoteScreen.getInstance(this); // This is screen 1
        confirmVoteScreen = ConfirmVoteScreen.getInstance(this); // This is screen 2
        
        screens.add(initialScreen);
        screens.add(selectionVoteScreen);
        screens.add(confirmVoteScreen);
        
        this.show(screens.get(0));
    }

    public void showScreen(int show, int hide) {
        if( ((show == 1) && (!selectionVoteScreen.isInitialization())) || (vote == null) )
            selectionVoteScreen.init(this);
        
        screens.get(hide).setVisible(false);
        screens.get(show).setVisible(true);
        
        this.getMainFrame().add(screens.get(show), java.awt.BorderLayout.CENTER);
    }
    
    /**
     * This method is to initialize the specified window by injecting resources.
     * Windows shown in our application come fully initialized from the GUI
     * builder, so this additional configuration is not needed.
     */
    @Override protected void configureWindow(java.awt.Window root) {
    }

    /**
     * A convenient static getter for the application instance.
     * @return the instance of MaquinaVotarApp
     */
    public static MaquinaVotarApp getApplication() {
        return Application.getInstance(MaquinaVotarApp.class);
    }

    /**
     * Main method launching the application.
     */
    public static void main(String[] args) {
        launch(MaquinaVotarApp.class, args);
    }
}
